package com.ruoyi.web.controller.glue;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.GlueCategoryType;
import com.ruoyi.system.service.IGlueCategoryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分类类型Controller
 *
 * @author ruoyi
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/system/type")
public class GlueCategoryTypeController extends BaseController
{
    @Autowired
    private IGlueCategoryTypeService glueCategoryTypeService;

    /**
     * 查询分类类型列表
     * @return {@link GlueCategoryType}
     */
    //@PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(GlueCategoryType glueCategoryType)
    {
        startPage();
        List<GlueCategoryType> list = glueCategoryTypeService.selectGlueCategoryTypeList(glueCategoryType);
        return getDataTable(list);
    }

    /**
     * 导出分类类型列表
     */
    //@PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "分类类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GlueCategoryType glueCategoryType)
    {
        List<GlueCategoryType> list = glueCategoryTypeService.selectGlueCategoryTypeList(glueCategoryType);
        ExcelUtil<GlueCategoryType> util = new ExcelUtil<GlueCategoryType>(GlueCategoryType.class);
        util.exportExcel(response, list, "分类类型数据");
    }

    /**
     * 获取分类类型详细信息
     * @return {@link GlueCategoryType}
     */
    //@PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(glueCategoryTypeService.selectGlueCategoryTypeById(id));
    }

    /**
     * 新增分类类型
     */
    //@PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "分类类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GlueCategoryType glueCategoryType)
    {
        return toAjax(glueCategoryTypeService.insertGlueCategoryType(glueCategoryType));
    }

    /**
     * 修改分类类型
     */
    //@PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "分类类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GlueCategoryType glueCategoryType)
    {
        return toAjax(glueCategoryTypeService.updateGlueCategoryType(glueCategoryType));
    }

    /**
     * 删除分类类型
     */
    //@PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "分类类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(glueCategoryTypeService.deleteGlueCategoryTypeByIds(ids));
    }
}
